package com.laolang.shop.modules.front.logic.api.impl;

import com.laolang.shop.modules.front.logic.api.AuthApiLogic;
import com.laolang.shop.modules.member.service.MemberService;
import com.laolang.shop.modules.sys.consts.entity.SysUserConst;
import com.laolang.shop.modules.sys.entity.SysTenant;
import com.laolang.shop.modules.sys.entity.SysUser;
import com.laolang.shop.modules.sys.service.SysTenantService;
import com.laolang.shop.modules.sys.service.SysUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @author khlbat
 * @version 1.0
 * @date 2020/11/1 20:46
 */
@Slf4j
@AllArgsConstructor
@Service
public class AuthApiLogicImpl implements AuthApiLogic {

    private final SysUserService sysUserService;
    private final SysTenantService sysTenantService;
    private final MemberService memberService;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void register(String phone, String pwd) {
        SysTenant sysTenant = sysTenantService.createSysTenant(phone);
        SysUser sysUser = sysUserService.createSysUser(phone, pwd, sysTenant.getId(), SysUserConst.Type.PERSONAL.getValue());
        memberService.createMember(sysUser.getId(), sysUser.getTenantId());
    }


}
